<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .lili {
            background-color: #ff0;
            font-size: 20px;
            margin-bottom: 10px;

        }
    </style>
</head>
<ul>

</ul>

<body>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
    <script>
        let oul = document.querySelector('ul');
        $.ajax({
            url: 'http://apis.juhe.cn/goodbook/catalog',
            dataType: 'jsonp',

            data: {
                key: 'f24f2e2303c8df02e79afe7f92853866'
            },
            success(res) {


                let str = '';
                res.result.forEach(item => {
                    str += `<li id="${item.id}"  class="lili">${item.catalog}</li>`;
                    console.log(item);

                });

                oul.innerHTML = str
            }
        })

        oul.onclick = function (ev) {
            ev = ev || window.event;
            let target = ev.target || ev.srcElement;
            let id = target.id;
            console.log(id);

            $.ajax({
                url: 'http://apis.juhe.cn/goodbook/query',
                dataType: 'jsonp',

                data: {
                    key: 'f24f2e2303c8df02e79afe7f92853866',
                    catalog_id: id,
                    pn: 1,
                    rn: 10
                },
                success(res) {
                    console.log(res);

                    let str = '';
                    res.result.data.forEach(item => {
                        str += `<li >${item.title}</li>`;


                    });

                    target.innerHTML = str
                }
            })

        }
    </script>
</body>

</html>